<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="3" :sm="8">
            <a-form-item
              label="姓名"
              :maxLength="50">
              <a-input placeholder="请输入姓名" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
            <a-col :md="3" :sm="8">
                <a-form-item
                        label="编号"
                        :maxLength="50">
                    <a-input placeholder="请输入编号" v-model="queryParam.shorter"></a-input>
                </a-form-item>
            </a-col>
          <a-col :md="4" :sm="8" >
            <a-form-item
                    label="检查时间"
                    :maxLength="50">
              <a-range-picker @change="onChange" v-model="queryParam.timeinfo" format="YYYY-MM-DD"/>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="8" v-if="!havesch">
            <a-form-item
                    label="学校"
                    :maxLength="50">
              <a-select
                      style="width: 100%"
                      placeholder="请选择学校"
                      @change="classChange"
                      optionFilterProp="children"
                      v-model="queryParam.schid">
                <a-select-option
                        v-for="(demo,index) in schList"
                        :key="index.toString()"
                        :value="parseInt(demo.id)">
                  {{ demo.name }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="3" :sm="8">
            <a-form-item
                    label="年级"
                    :maxLength="50">
              <a-select
                      style="width: 100%"
                      placeholder="请选择学校"
                      @change="classChange1"
                      optionFilterProp="children"
                      v-model="queryParam.gradeId">
                <a-select-option
                        v-for="(demo,index) in gradeList"
                        :key="index.toString()"
                        :value="parseInt(demo.id)">
                  {{ demo.name }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="3" :sm="8">
            <a-form-item
                    label="班级"
                    :maxLength="50">
              <a-select
                      style="width: 100%"
                      placeholder="请选择班级"
                      optionFilterProp="children"
                      v-model="queryParam.classId">
                <a-select-option
                        v-for="(demo,index) in classList"
                        :key="index.toString()"
                        :value="parseInt(demo.id)">
                  {{ demo.name }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
         <a-col :md="4" :sm="8" >
            <a-form-item
                    label="检查状态"
                    :maxLength="50">
              <a-select
                      style="width: 100%"
                      placeholder="请选择检查结果"
                      v-model="queryParam.jcjg">
                  <a-select-option value="1">已检</a-select-option>
                  <a-select-option value="2">漏项</a-select-option>
              </a-select>
            </a-form-item>
         </a-col>
          </template>
             <template v-if="toggleSearchStatus">
          <a-col  :md="4" :sm="8">
              <a-form-item
                      label="打印状态"
                      :maxLength="50">
                  <a-select
                          style="width: 100%"
                          placeholder="请选择检查结果"
                          v-model="queryParam.ptflag">
                      <a-select-option value="0">未打印</a-select-option>
                      <a-select-option value="1">已打印</a-select-option>
                  </a-select>
              </a-form-item>
              </a-col>
          </template>
          <a-col :md="4" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="$refs.table.refresh(true)" icon="search">查询</a-button>
              <a-button
                @click="() => {this.$objToReset(queryParam),$refs.table.refresh(true)}"
                icon="reload"
                style="margin-left: 8px">重置</a-button>
               <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>

          </a-col>
        </a-row>
      </a-form>
      <div class="table-operator">
       <!-- -->
        <a-button @click="exports" type="primary" icon="export" >导出</a-button>
        <a-button @click="handelVj" type="primary" icon="plus" >查看未检</a-button>
        <!--<a-button @click="$refs.modalEdit.add()" type="primary" icon="plus" >添加</a-button>-->

        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item>
              <a-popconfirm
                  title="确定删除吗?"
                  @confirm="() => handleDelete()"
                  >
                <a><a-icon type="delete"/>删除</a>
              </a-popconfirm>
            </a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px">批量操作<a-icon type="down"/></a-button>
        </a-dropdown>
        <span>
           <span style="font-size: 14px;color: blue;margin-left: 20px">学生总数：{{ studentnums }}人</span>
           <span style="font-size: 14px;color: blue;margin-left: 20px">已检：{{ yjnum }}人</span>
           <span style="font-size: 14px;color: blue;margin-left: 20px" v-if="vjnum>=0">未检：{{ vjnum }}人</span>
           <span style="font-size: 14px;color: blue;margin-left: 20px">漏项：{{ lxnum }}人</span>
        </span>
      </div>
      <s-table
        ref="table"
        rowKey="id"
        size="middle"
        :scroll="scrollCss"
        :columns="columns"
        :alert="options.alert"
        :data="loadData">
        <template slot="sflag" slot-scope="text, record">
          <span v-if="record.workshilibiaoflag==1&&record.workmanualflag==1&&record.workyanguangflag==1">已检</span>
          <span v-else style="color: red">漏项</span>
        </template>
          <template slot="ptflag" slot-scope="text, record">
              <span v-if="record.ptflag&&record.ptflag==1" style="color: blue">已打印</span>
              <span v-else style="color: red" >未打印</span>
          </template>
        <template slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" >
            <a-icon type="edit"/>编辑</a>
          <a-divider type="vertical"/>
            <a @click="handelPrint(record)" ><a-icon/> 打印报告</a>
            <a-divider type="vertical"/>
          <a @click="handelView(record)" ><a-icon/> 查看</a>
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() =>handleDelete(record.id)" >
            <a>删除</a>
          </a-popconfirm>
        </template>
      </s-table>

      <eye-student-test-record-edit ref="modalEdit" @ok="modalEditOk"></eye-student-test-record-edit>
      <eye-student-test-record-view ref="modalView"></eye-student-test-record-view>
      <eye-student-list-vj ref="vj" @cancle="modalEditOk" ></eye-student-list-vj>
        <print-modal ref="print" @close="modalEditOk" ></print-modal>
    </div>
  </a-card>
</template>

<script>
  import { STable, Ellipsis } from '@/components'
  import { deleteAction, postAction,getAction,fileAction } from '@/api/manage'
  import { mixin } from '@/utils/mixin'
  import EyeStudentTestRecordEdit from './EyeStudentTestRecordEdit'
  import EyeStudentTestRecordView from './EyeStudentTestRecordView'
  import EyeStudentListVj from "./EyeStudentListVj";
  import PrintModal from "./PrintModal";

  export default {
    name: 'EyeStudentTestRecordList',
    mixins: [mixin],
    components: {PrintModal, EyeStudentListVj, STable, Ellipsis, EyeStudentTestRecordEdit, EyeStudentTestRecordView },
    data () {
      return {
          scrollCss:{x: 2500, y: document.body.clientHeight - 280},
        visible: false,
          toggleSearchStatus:false,
        // 查询条件
        queryParam: {
          title: '',
            schid:undefined
        },
          studentnums:undefined,
          yjnum:undefined,
          vjnum:undefined,
          lxnum:undefined,
        // 表头
        // 如果需要字典，那么需要在columns列中加入 customRender: (text) => this.$sysDictFilter(text, 'xxxx')xxxx 为dataIndex
        columns: [
            {
                title: '学校',
                dataIndex: 'schname',
                width: 220
            },
            {
                title: '班级',
                dataIndex: 'classname',
                width: 80
            },
          {
            title: '学生',
            dataIndex: 'studentname',
              width: 80
          },
            {
                title: '检查时间',
                dataIndex: 'createtime',
                width: 160
            },
            {
                title: '检查状态',
                scopedSlots: { customRender: 'sflag' },
                width: 80
            },
            {
                title: '打印状态',
                scopedSlots: { customRender: 'ptflag' },
                width: 80
            },
          {
            title: '视力左',
            dataIndex: 'eyeleftdata',
              width: 60
          },
          {
            title: '视力右',
            dataIndex: 'eyerightdata',
              width: 60
          },
          {
            title: '矫正视力左',
            dataIndex: 'eyeleftclassdata',
              width: 90
          },
          {
            title: '矫正视力右',
            dataIndex: 'eyerightclassdata',
              width: 90
          },
            {
                title: '右球镜',
                dataIndex: 'yanguangyouqiujing',
                width: 60
            },
            {
                title: '右柱镜',
                dataIndex: 'yanguangyouzhujing',
                width: 60
            },
            {
                title: '右轴位',
                dataIndex: 'yanguangyouzhouwei',
                width: 60
            },
            {
                title: '左球镜',
                dataIndex: 'yanguangzuoqiujing',
                width: 60
            },
            {
                title: '左柱镜',
                dataIndex: 'yanguangzuozhujing',
                width: 60
            },
            {
                title: '左轴位',
                dataIndex: 'yanguangzuozhouwei',
                width: 60
            },
/*          {
            title: '视力表是否做',
            dataIndex: 'workshilibiaoflag',
            customRender: (text) => this.$sysDictFilter(text, 'workShilibiaoFlag')
          },
          {
            title: '手动输入是否做',
            dataIndex: 'workmanualflag',
            customRender: (text) => this.$sysDictFilter(text, 'workManualFlag')
          },
          {
            title: '验光仪是否做',
            dataIndex: 'workyanguangflag',
            customRender: (text) => this.$sysDictFilter(text, 'workYanguangFlag')
          },
          {
            title: '录入人-视力表',
            dataIndex: 'createbyshilibiao'
          },
          {
            title: '录入人-手动输入',
            dataIndex: 'createbymanual'
          },
          {
            title: '录入人-验光仪',
            dataIndex: 'createbyyanguang'
          },
          {
            title: '视力表-时间',
            dataIndex: 'dealtimeshilibiao'
          },
          {
            title: '手动输入-时间',
            dataIndex: 'dealtimemanual'
          },
          {
            title: '验光仪-时间',
            dataIndex: 'dealtimeyanguang'
          },*/
          {
            title: '色觉',
            dataIndex: 'manualsejue',
              width: 60
          },
          {
            title: '眼位',
            dataIndex: 'manualyanwei',
              width: 60
          },
          {
            title: '眼球运动',
            dataIndex: 'manualyanqiuyundong',
              width: 80
          },
          {
            title: '眼睑内翻倒睫',
            dataIndex: 'manualyanjianneifan',
              width: 100
          },
          {
            title: '眼睑肿物',
            dataIndex: 'manualyanlianzhongwu',
              width: 80
          },
          {
            title: '眼睑上睑下垂',
            dataIndex: 'manualyanlianshanglian',
              width: 100
          },
          {
            title: '结膜充血',
            dataIndex: 'manualjiemochongxie',
              width: 80
          },
          {
            title: '结膜充血分泌物',
            dataIndex: 'manualjiemochongxiemiwu',
              width: 120
          },
          {
            title: '备注',
            dataIndex: 'manualremark',
              width: 60
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            scopedSlots: { customRender: 'action' }
          }
        ],
          schList:[],
          gradeList:[],
          classList:[],
          havesch:false,
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          console.log('loadData.parameter', parameter)
          return postAction(this.url.list, Object.assign(parameter, this.queryParam))
              .then(res => {
                  console.log(res)
                  if(res.result.company&&res.result.company.schid){
                      this.queryParam.schid = res.result.company.schid
                      this.havesch=true
                      this.classChange()
                  }
                  this.vjnum = res.result.vjnum
                  this.studentnums = res.result.studentnums
                  this.yjnum = res.result.yjnum
                  this.lxnum = res.result.lxnum
                return res.result
              })
        },
        selectedRowKeys: [],
        options: {
          alert: {
            clear: () => {
              this.selectedRowKeys = []
            }
          },
          rowSelection: {
            selectedRowKeys: this.selectedRowKeys,
            onChange: this.onSelectChange,
            type: 'checkbox'
          }
        },
        url: {
          list: '/system/eyeStudentTestRecord/list',
          delete: '/system/eyeStudentTestRecord/delete',
            classList: '/system/eyeClass/getList',
            listExcel:'/system/eyeStudentTestRecord/listExcel'
        }
      }
    },
    computed: {},
      created () {
          this.getclasslist(undefined,1)
      },
    methods: {
        handleToggleSearch () {
            this.toggleSearchStatus = !this.toggleSearchStatus
        },
        handelVj(){
            if(this.queryParam.times){
                this.$refs.vj.edit(this.queryParam)
            }else{
                this.$message.error('请选择检查时间!')
            }
        },
        handelPrint(record){
            this.$refs.print.show(record,"打印报告")
        },
      // 删除
      handleDelete (record) {
        if (!record) {
          // 如果没有传入，那么批量删除
          record = this.selectedRowKeys.join(',')
        }
        deleteAction(this.url.delete, { ids: record }).then((resp) => {
          this.$message.success('删除成功!')
          this.$refs.table.refresh(true)
        })
      },
      // 用户编辑
      handleEdit (record) {
        this.$refs.modalEdit.edit(record)
      },
      searchQuery () {
        this.$refs.table.refresh(true)
      },
      // 保存刷新
      modalEditOk () {
        this.$refs.table.refresh()
      },
      // 查看
      handelView (record) {
        this.$refs.modalView.show(record)
      },
      //开启选择
      onSelectChange (selectedRowKeys) {
         console.log('selectedRowKeys changed: ', selectedRowKeys)
         this.selectedRowKeys = selectedRowKeys
      },
        onChange (value, dateString) {
            console.log(dateString[0], dateString[1])
            this.queryParam.times = dateString[0] + ' ~ ' + dateString[1]
        },
        classChange(){
            this.getclasslist(this.queryParam.schid,2)
        },
        classChange1(){
            this.getclasslist(this.queryParam.gradeId,3)
        },
        getclasslist(parentid,orgflag){
            getAction(this.url.classList, { 'parendId': parentid,'orgFlag':orgflag }).then(res => {
                this.$nextTick(() => {
                    if(orgflag==1){
                        this.schList=res.result.data
                    }else if(orgflag==2){
                        this.gradeList = res.result.data
                    }else if(orgflag==3){
                        this.classList = res.result.data
                    }
                })
            })
        },
        exports(){
            if(!this.queryParam.schid){
                this.$message.warning('导出请选择学校!')
            }else if(!this.queryParam.times){
                this.$message.warning('导出请选择时间!')
            }else {
                fileAction(this.url.listExcel, this.queryParam).then(res => {

                })
            }
        },
    },
    watch: {}
  }
</script>
<style scoped>
</style>
